﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using HumanManagement.BusinessObjects;

namespace HumanManagement.DataAccess
{
	public class ProfessionalKnowledgeDA
	{

		#region ***** Init Methods ***** 
		public ProfessionalKnowledgeDA()
		{
		}
		#endregion

		#region ***** Get Methods ***** 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public ProfessionalKnowledge Populate(IDataReader myReader)
		{
			ProfessionalKnowledge obj = new ProfessionalKnowledge();
			obj.ID = (int) myReader["ID"];
			obj.PersonalProfileID = (int) myReader["PersonalProfileID"];
			obj.ProfessionalKnowledgeLevelID = (int) myReader["ProfessionalKnowledgeLevelID"];
			obj.ProfessionalKnowledgeTrainingMethodID = (int) myReader["ProfessionalKnowledgeTrainingMethodID"];
			obj.ProfessionalKnowledgeTrainingSchoolID = (int) myReader["ProfessionalKnowledgeTrainingSchoolID"];
			obj.ProfessionalKnowledgeMajorID = (int) myReader["ProfessionalKnowledgeMajorID"];
			obj.ProfessionalKnowledgeGraduationGradeID = (int) myReader["ProfessionalKnowledgeGraduationGradeID"];
			obj.EducationDegreeID = (int) myReader["EducationDegreeID"];
			obj.FromDate = (DateTime) myReader["FromDate"];
			obj.ToDate = (DateTime) myReader["ToDate"];
			obj.LastDate = (DateTime) myReader["LastDate"];
			obj.LastMakerID = (int) myReader["LastMakerID"];
			obj.LastApproverID = (int) myReader["LastApproverID"];
			obj.ProfessionalKnowledgeStatus = (string) myReader["ProfessionalKnowledgeStatus"];
			return obj;
		}

		/// <summary>
		/// Get ProfessionalKnowledge by id
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns>ProfessionalKnowledge</returns>
		public ProfessionalKnowledge GetByID(int id)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ProfessionalKnowledge_GetByID", Data.CreateParameter("ID", id)))
			{
				if (reader.Read())
				{
					return Populate(reader);
				}
				return null;
			}
		}

		/// <summary>
		/// Get all of ProfessionalKnowledge
		/// </summary>
		/// <returns>List<<ProfessionalKnowledge>></returns>
		public List<ProfessionalKnowledge> GetList()
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ProfessionalKnowledge_Get"))
			{
				List<ProfessionalKnowledge> list = new List<ProfessionalKnowledge>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ProfessionalKnowledge
		/// </summary>
		/// <returns>DataSet</returns>
		public DataSet GetDataSet()
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ProfessionalKnowledge_Get");
		}


		/// <summary>
		/// Get all of ProfessionalKnowledge paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>List<<ProfessionalKnowledge>></returns>
		public List<ProfessionalKnowledge> GetListPaged(int recperpage, int pageindex)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ProfessionalKnowledge_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex)))
			{
				List<ProfessionalKnowledge> list = new List<ProfessionalKnowledge>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ProfessionalKnowledge paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetPaged(int recperpage, int pageindex)
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ProfessionalKnowledge_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex));
		}





		#endregion

		#region ***** Add Update Delete Methods ***** 
		/// <summary>
		/// Add a new ProfessionalKnowledge within ProfessionalKnowledge database table
		/// </summary>
		/// <param name="obj">ProfessionalKnowledge</param>
		/// <returns>key of table</returns>
		public int Add(ProfessionalKnowledge obj)
		{
			DbParameter parameterItemID = Data.CreateParameter("ID", obj.ID);
			parameterItemID.Direction = ParameterDirection.Output;
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ProfessionalKnowledge_Add"
							,parameterItemID
							,Data.CreateParameter("PersonalProfileID", obj.PersonalProfileID)
							,Data.CreateParameter("ProfessionalKnowledgeLevelID", obj.ProfessionalKnowledgeLevelID)
							,Data.CreateParameter("ProfessionalKnowledgeTrainingMethodID", obj.ProfessionalKnowledgeTrainingMethodID)
							,Data.CreateParameter("ProfessionalKnowledgeTrainingSchoolID", obj.ProfessionalKnowledgeTrainingSchoolID)
							,Data.CreateParameter("ProfessionalKnowledgeMajorID", obj.ProfessionalKnowledgeMajorID)
							,Data.CreateParameter("ProfessionalKnowledgeGraduationGradeID", obj.ProfessionalKnowledgeGraduationGradeID)
							,Data.CreateParameter("EducationDegreeID", obj.EducationDegreeID)
							,Data.CreateParameter("FromDate", obj.FromDate)
							,Data.CreateParameter("ToDate", obj.ToDate)
							,Data.CreateParameter("LastDate", obj.LastDate)
							,Data.CreateParameter("LastMakerID", obj.LastMakerID)
							,Data.CreateParameter("LastApproverID", obj.LastApproverID)
							,Data.CreateParameter("ProfessionalKnowledgeStatus", obj.ProfessionalKnowledgeStatus)
			);
			return (int)parameterItemID.Value;
		}

		/// <summary>
		/// updates the specified ProfessionalKnowledge
		/// </summary>
		/// <param name="obj">ProfessionalKnowledge</param>
		/// <returns></returns>
		public void Update(ProfessionalKnowledge obj)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ProfessionalKnowledge_Update"
							,Data.CreateParameter("ID", obj.ID)
							,Data.CreateParameter("PersonalProfileID", obj.PersonalProfileID)
							,Data.CreateParameter("ProfessionalKnowledgeLevelID", obj.ProfessionalKnowledgeLevelID)
							,Data.CreateParameter("ProfessionalKnowledgeTrainingMethodID", obj.ProfessionalKnowledgeTrainingMethodID)
							,Data.CreateParameter("ProfessionalKnowledgeTrainingSchoolID", obj.ProfessionalKnowledgeTrainingSchoolID)
							,Data.CreateParameter("ProfessionalKnowledgeMajorID", obj.ProfessionalKnowledgeMajorID)
							,Data.CreateParameter("ProfessionalKnowledgeGraduationGradeID", obj.ProfessionalKnowledgeGraduationGradeID)
							,Data.CreateParameter("EducationDegreeID", obj.EducationDegreeID)
							,Data.CreateParameter("FromDate", obj.FromDate)
							,Data.CreateParameter("ToDate", obj.ToDate)
							,Data.CreateParameter("LastDate", obj.LastDate)
							,Data.CreateParameter("LastMakerID", obj.LastMakerID)
							,Data.CreateParameter("LastApproverID", obj.LastApproverID)
							,Data.CreateParameter("ProfessionalKnowledgeStatus", obj.ProfessionalKnowledgeStatus)
			);
		}

		/// <summary>
		/// Delete the specified ProfessionalKnowledge
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns></returns>
		public void Delete(int id)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ProfessionalKnowledge_Delete", Data.CreateParameter("ID", id));
		}
		#endregion
	}
}
